/*
 * Copyright (c) 2009 John Pritchard, WTKX Project Group
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package wtkx.ui;

import wtkx.io.CSS;

/**
 * 
 * @author jdp
 */
public final class Display
    extends Object
    implements jbxml.Value
{


    public enum Type {
        Inline("inline"),
        Block("block"),
        InlineBlock("inline-block"),
        ListItem("list-item"),
        RunIn("run-in"),
        Compact("compact"),
        Table("table"),
        InlineTable("inline-table"),
        TableRowGroup("table-row-group"),
        TableHeaderGroup("table-header-group"),
        TableFooterGroup("table-footer-group"),
        TableRow("table-row"),
        TableColumnGroup("table-column-group"),
        TableColumn("table-column"),
        TableCell("table-cell"),
        TableCaption("table-caption"),
        Ruby("ruby"),
        RubyBase("ruby-base"),
        RubyText("ruby-text"),
        RubyBaseGroup("ruby-base-group"),
        RubyTextGroup("ruby-text-group"),
        Template("template"),
        None("none");


        public final String id;

        private Type(String id){
            this.id = id;
        }

        public String toString(){
            return this.id;
        }

        public final static Type decode(String value){
            return valueOf(CSS.ClassCamel(value));
        }
    }


    public Type type;


    public Display() {
        super();
        this.type = Type.None;
    }
    public Display(Type type){
        super();
        if (null != type)
            this.type = type;
        else
            throw new IllegalArgumentException();
    }
    public Display(String css){
        super();
        this.fromString(css);
    }


    public boolean isNotNone(){
        return (Type.None != this.type);
    }
    public void setNone(){
        this.type = Type.None;
    }
    public void setBlock(){
        this.type = Type.Block;
    }    
    public void fromString(String css){
        if (null != css)
            this.type = Type.decode(css);
        else
            throw new IllegalArgumentException();
    }
    public int hashCode(){
        return this.type.hashCode();
    }
    public String toString(){
        return this.type.toString();
    }
    public boolean equals(Object that){
        if (this == that)
            return true;
        else if (null == that)
            return false;
        else if (that instanceof Display)
            return this.type.equals(((Display)that).type);
        else
            return false;
    }
}
